package cn.itcast.spring.demo1;

import static org.junit.Assert.*;

import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class UserDaoTest {

	@Test
	public void getUserEat() throws Exception {
		/*UserDao dao = new UserDaoImpl();
		dao.eat();*/
		//在spring当中applicationContext是我们容器的一个子接口
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		UserDaoImpl bean = (UserDaoImpl) context.getBean("userDao");
		bean.eat();
		System.out.println(bean.getUsername());
	}
	
	/**
	 * 使用xmlBeanFactory创建容器，会发现这种方法已经过期了，不推荐使用了。
	 * @throws Exception
	 */
	@Test
	public void getBeanFactory1() throws Exception {
		XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
	}
	
	/**
	 * 第二种获取容器的方式，通过使用classpathXmlApplicationContext来获取容器
	 * @throws Exception
	 */
	@Test
	public void getBeanFactory2() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		context.getBean("userDao");
	}
	
	/**
	 * 通过使用FileSystemXmlApplicationContext 来获取容器的时候，需要传入spring配置文件的绝对路径
	 * @throws Exception
	 */
	@Test
	public void getBeanFactory3() throws Exception {
		ApplicationContext context = new FileSystemXmlApplicationContext("E:\\MyWorkSystem\\eclipseWorkSpace_development_branchs\\springDay01\\src\\main\\resources\\applicationContext.xml");
		
		
		
	}
	
	
	
	
	
}
